package heima.lm.oschina.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import heima.lm.oschina.BaseApplication;
import heima.lm.oschina.R;
import heima.lm.oschina.bean.Event;
import heima.lm.oschina.utils.UIUtils;

/**
 * Created by Administrator on 2017/4/7.
 */

public class RecentActivitiesAdapter extends BaseRecyclerViewAdapter{
    public RecentActivitiesAdapter(List list) {
        super(list);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(BaseApplication.mApp).inflate(R.layout.item_recent_activities,parent,false);
        return new ActivitiesViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        ActivitiesViewHolder viewHolder = (ActivitiesViewHolder) holder;
        Event event = (Event) mList.get(position);
        //设置item的值
        Glide.with(UIUtils.getContext()).load(event.getCover()).fitCenter().into(viewHolder.imgEventsCover);//加载图片
        viewHolder.tvEventTitle.setText(event.getTitle());
        viewHolder.tvEventsSpot.setText(event.getSpot());
        viewHolder.tvEventsStartTime.setText(event.getStartTime());
        viewHolder.imgEventsStatusChecked.setVisibility(View.VISIBLE);
        viewHolder.imgEventsCover.setImageResource(event.getId());
    }

    class ActivitiesViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_events_cover)
        ImageView imgEventsCover;
        @BindView(R.id.tv_events_title)
        TextView tvEventTitle;
        @BindView(R.id.tv_events_starttime)
        TextView tvEventsStartTime;
        @BindView(R.id.tv_events_spot)
        TextView tvEventsSpot;
        @BindView(R.id.img_events_status_checked)
        ImageView imgEventsStatusChecked;

        public ActivitiesViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
